package com.atguigu.springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @author durant
 * @create 2021-11-01 14:36
 */
@Controller
public class testcontroller {
//    @RequestMapping("/")
//    public String index(){
//
//        return "index";
//    }
    @RequestMapping("/test_view")
    public String test_view(){

        return "test_view";
    }
    @RequestMapping("/testServletAPI")
    public String testServletAPI(HttpServletRequest request){
        request.setAttribute("testScope", "hello,servletAPI");
        return "success";
    }
    @RequestMapping("/testModelAndView")
    public ModelAndView testModelAndView(ModelAndView mav){
        mav.addObject("testScope", "hello,testModelAndView");
        mav.setViewName("success");
        return mav;
    }


    @RequestMapping("/testModel")
    public String testModel(Model model){
        model.addAttribute("testScope", "hello,Model");
        System.out.println("model:       "+model.getClass().getName());
        return "success";
    }
    @RequestMapping("/testMap")
    public String testMap(Map<String, Object> map){
        map.put("testScope", "hello,Map");
        System.out.println("map:       "+map.getClass().getName());
        return "success";
    }
    @RequestMapping("/testModelMap")
    public String testMap(ModelMap map){
        map.put("testScope", "hello,ModelMap");
        System.out.println("modelmap:       "+map.getClass().getName());
        return "success";
    }
    @RequestMapping("/testSession")
    public String testSession(HttpSession session){
        session.setAttribute("testSession", "sessionvalue");
        return "success";
    }
}
